package com.haoma.controller;

import com.haoma.dto.AdminDto;
import com.haoma.entity.Admin;
import com.haoma.result.Result;
import com.haoma.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * Description:管理员接口
 */
@RestController
@RequestMapping("/admin/user")
public class AdminController {

    @Autowired
    private AdminService adminService;

    // 登录方法
    @PostMapping("/login")
    public Result login(@RequestBody Admin admin) {
        System.out.println(admin);
        return adminService.login(admin);
    }

    // 退出登录
    @GetMapping("/logout")
    public Result logout() {
        return adminService.logout();
    }

    // 重置密码
    @PostMapping("/reset")
    public Result reset(@RequestBody AdminDto adminDto) {
        return adminService.reset(adminDto);
    }

    // 上传头像
    @PostMapping("/fileUpload")
    public Result fileUpload(@RequestParam("file") MultipartFile multipartFile) {
        String fileUrl = adminService.fileUpload(multipartFile);
        return Result.success(fileUrl);
    }

    /**
     * 访客
     * @return
     */
    @GetMapping("/view")
    public Result onView(){
        Admin admin = adminService.onView();
        return Result.success(admin);
    }
}
